package com.campus.controller;

import com.campus.model.Class;
import com.campus.model.TeachingStudentInClass;
import com.campus.service.ClassService;
import com.campus.web.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.campus.common.BusinessConstants.API_BASE;

@RestController
@RequestMapping( "/classes")
@Slf4j
public class ClassController {

    private final ClassService classService;

    @Autowired
    public ClassController(ClassService classService) {
        this.classService = classService;
    }

    @PostMapping("/create")
    public ResponseEntity<String> createClass(@RequestBody Class cls) {
        int result = classService.createClass(cls);
        return result > 0 ? ResponseEntity.ok("Class created successfully") : ResponseEntity.status(500).body("Failed to create class");
    }

    @PutMapping("/{id}/update")
    public ResponseEntity<String> updateClass(@PathVariable int id, @RequestBody Class cls) {
        cls.setId(id);
        int result = classService.updateClass(cls);
        return result > 0 ? ResponseEntity.ok("Class updated successfully") : ResponseEntity.status(500).body("Failed to update class");
    }

    @PostMapping("/{classId}/add-students")
    public ResponseEntity<String> addStudentsToClass(@PathVariable int classId, @RequestBody List<Integer> studentIds) {
        int result = classService.addStudentsToClass(classId, studentIds);
        return result > 0 ? ResponseEntity.ok("Students added successfully") : ResponseEntity.status(500).body("Failed to add students");
    }

    @PostMapping("/{classId}/assign-teachers")
    public ResponseEntity<String> assignTeachersToClass(@PathVariable int classId, @RequestBody List<Integer> teacherIds) {
        int result = classService.assignTeachersToClass(classId, teacherIds);
        return result > 0 ? ResponseEntity.ok("Teachers assigned successfully") : ResponseEntity.status(500).body("Failed to assign teachers");
    }
}
